﻿/**************************************************************
* Copyright (C) 2022 www.eipflow.com 孙泽伟版权所有(盗版必究)
*
* 作者: 孙泽伟(QQ 1039318332)
* 创建时间: 2022/01/12 22:40:15
* 文件名: 
* 描述: 
* 
* 修改历史
* 修改人：
* 时间：
* 修改说明：
*
**************************************************************/

using EIP.Common.Models.Paging;
using EIP.System.Models.Enums;
using System;
using System.Collections.Generic;

namespace EIP.System.Models.Dtos.WorkSheet
{
    /// <summary>
    /// 
    /// </summary>
    public class SystemWorkSheetTableFieldInput
    {
        /// <summary>
        /// 表单Id
        /// </summary>
        public Guid ZeroCodeId { get; set; }

        /// <summary>
        /// 字段信息
        /// </summary>
        public string Columns { get; set; }
    }

    /// <summary>
    /// 
    /// </summary>
    public class SystemWorkSheetTableFieldDetailInput
    {
        /// <summary>
        /// 字段名称
        /// </summary>
        public string Key { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        public string Label { get; set; }

        /// <summary>
        /// 修改前别名
        /// </summary>
        public string ModelBefore { get; set; }

        /// <summary>
        /// 别名
        /// </summary>
        public string Model { get; set; }

        /// <summary>
        /// 帮助
        /// </summary>
        public string Help { get; set; }

        /// <summary>
        /// 控件类型:默认为文本
        /// </summary>
        public string Type { get; set; } = "text";

        /// <summary>
        /// 
        /// </summary>
        public SystemDataBaseColumnsOptionInput Options { get; set; } = new SystemDataBaseColumnsOptionInput();

        /// <summary>
        /// 
        /// </summary>
        public List<SystemWorkSheetTableFieldDetailInput> Children { get; set; } = new List<SystemWorkSheetTableFieldDetailInput>();

        /// <summary>
        /// 值
        /// </summary>
        public object Value { get; set; }

        /// <summary>
        /// 数据类型
        /// </summary>
        public string FieldType
        {
            get
            {
                switch (Type)
                {
                    case "input":
                    case "textarea":
                        return $"varchar({Options.MaxLength})";
                    case "enumber":
                    case "total":
                    case "formula":
                        if (Options.Type == "number")
                        {
                            return $"decimal(16,{Options.Number.Places})";
                        }
                        else if (Options.Type == "time")
                        {
                            switch (Options.Time.Type)
                            {
                                case "durationBetweenDates":
                                    return $"decimal(16,{Options.Time.DurationBetweenDates.Places})";
                                default:
                                    break;
                            }
                            return $"decimal(16,{Options.Number.Places})";
                        }
                        else if (Options.Type == "func")
                        {
                            switch (Options.Func.Type)
                            {
                                case "number":
                                    return $"decimal(16,{Options.Func.Number.Places})";
                                default:
                                    break;
                            }
                        }
                        return "varchar(256)";
                    case "date":
                        return "datetime";
                    case "time":
                        return "varchar(8)";
                    case "rate":
                    case "slider":
                        return "decimal(16,2)";
                    case "editor":
                    case "sign":
                    case "textCombination":
                    case "autoComplete":
                        return "text";
                    case "switch":
                        return "bool";
                    case "serialNo":
                    case "barCode":
                        return "varchar(256)";
                    case "icon":
                        return "varchar(64)";
                    case "correlation":
                    case "subtable":
                        return "json";
                    default:
                        return "varchar(128)";
                }

            }
        }
    }

    /// <summary>
    /// 
    /// </summary>
    public class SystemDataBaseColumnsOptionInput
    {
        /// <summary>
        /// 
        /// </summary>
        public bool Hidden { get; set; }
        /// <summary>
        /// 最大长度
        /// </summary>
        public int MaxLength { get; set; }

        /// <summary>
        /// 多选
        /// </summary>
        public bool Multiple { get; set; }

        /// <summary>
        /// 小数位数
        /// </summary>
        public int? Precision { get; set; }

        #region 编号

        /// <summary>
        /// 加载页面就显示
        /// </summary>
        public bool LoadDisplay { get; set; }

        /// <summary>
        /// 规则
        /// </summary>
        public List<SystemDataBaseColumnsOptionRuleInput> Rule { get; set; } = new List<SystemDataBaseColumnsOptionRuleInput>();

        /// <summary>
        /// 用户占用
        /// </summary>
        public bool UserOccupation { get; set; }
        #endregion

        #region 选项
        /// <summary>
        /// 父级Id
        /// </summary>
        public string Pid { get; set; }

        /// <summary>
        /// 选项
        /// </summary>
        public List<SystemDataBaseColumnsOptionOptionsInput> Options { get; set; } = new List<SystemDataBaseColumnsOptionOptionsInput>();
        #endregion

        #region 默认值
        /// <summary>
        /// 默认值
        /// </summary>
        public object DefaultValue { get; set; }

        /// <summary>
        /// 默认值配置字段
        /// </summary>
        public SystemDataBaseColumnsOptionDefaultValueConfig? DefaultValueConfig { get; set; }

        #endregion

        #region 关联记录
        /// <summary>
        /// 工作表
        /// </summary>
        public Guid? ZeroCodeId { get; set; }

        /// <summary>
        /// single单条，multiple多条
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// 显示类型(grid列表，select下拉，card卡片)
        /// </summary>
        public string ShowType { get; set; }

        /// <summary>
        /// 关联表显示字段
        /// </summary>
        public List<string> Columns { get; set; } = new List<string>();

        /// <summary>
        /// 双向关联配置
        /// </summary>
        public SystemDataBaseColumnsOptionCorrelationTwoWay TwoWay { get; set; } = new SystemDataBaseColumnsOptionCorrelationTwoWay();
        #endregion

        #region 汇总
        /// <summary>
        /// 汇总字段
        /// </summary>
        public string Key { get; set; }

        /// <summary>
        /// 汇总字段
        /// </summary>
        public string Field { get; set; }

        /// <summary>
        /// 四舍五入roundoff，向上舍入roundup，向下舍入rounddown
        /// </summary>
        public string RoundOff { get; set; }
        #endregion

        #region 公式
        /// <summary>
        /// 计算类型
        /// number
        /// </summary>
        public string CalculationMethod { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public SystemDataBaseColumnsOptionFormulaNumber Number { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public SystemDataBaseColumnsOptionFormulaTime Time { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public SystemDataBaseColumnsOptionFormulaFunc Func { get; set; }

        #endregion
    }
    /// <summary>
    /// 
    /// </summary>
    public class SystemDataBaseColumnsOptionFormulaNumber
    {
        /// <summary>
        /// 
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// 参与计算的字段值为空时，视为 0
        /// </summary>
        public bool ConvertNullToZero { get; set; }

        /// <summary>
        /// 小数位数
        /// </summary>
        public int Places { get; set; }

        /// <summary>
        /// 格式 roundoff 四舍五入,roundup 向上舍入,rounddown 向下舍入
        /// </summary>
        public string Round { get; set; }

        /// <summary>
        /// 省略末尾的 0
        /// </summary>
        public bool OmitLastZero { get; set; }

    }

    /// <summary>
    /// 
    /// </summary>
    public class SystemDataBaseColumnsOptionFormulaTime
    {
        /// <summary>
        /// 
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public SystemDataBaseColumnsOptionFormulaTimeDurationBetweenDates DurationBetweenDates { get; set; }
    }

    /// <summary>
    /// 
    /// </summary>
    public class SystemDataBaseColumnsOptionFormulaTimeDurationBetweenDates
    {
        /// <summary>
        /// 
        /// </summary>
        public int Places { get; set; }
    }
    /// <summary>
    /// 
    /// </summary>
    public class SystemDataBaseColumnsOptionFormulaFunc
    {
        /// <summary>
        /// 
        /// </summary>
        public string Type { get; set; }

        public SystemDataBaseColumnsOptionFormulaFuncTypeNumber Number { get; set; }
    }

    /// <summary>
    /// 
    /// </summary>
    public class SystemDataBaseColumnsOptionFormulaFuncTypeNumber
    {
        /// <summary>
        /// 
        /// </summary>
        public int Places { get; set; }

    }
    /// <summary>
    /// 默认值
    /// </summary>
    public class SystemDataBaseColumnsOptionDefaultValueConfig
    {
        /// <summary>
        /// 类型
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// 字段
        /// </summary>
        public List<SystemDataBaseColumnsOptionDefaultValueConfigField> Field { get; set; } = new List<SystemDataBaseColumnsOptionDefaultValueConfigField>();

        /// <summary>
        /// 
        /// </summary>
        public SystemDataBaseColumnsOptionDefaultValueConfigWorksheet WorkSheet { get; set; }
    }

    /// <summary>
    /// 默认值
    /// </summary>
    public class SystemDataBaseColumnsOptionDefaultValueConfigField
    {
        /// <summary>
        /// 类型
        /// </summary>
        public string Key { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string ZeroCodeId { get; set; }

    }
    /// <summary>
    /// 默认值
    /// </summary>
    public class SystemDataBaseColumnsOptionDefaultValueConfigWorksheet
    {
        /// <summary>
        /// 查询条件
        /// </summary>
        public Filter Filters { get; set; }

        /// <summary>
        /// 查询到多条时1获取第一条，不获取
        /// </summary>
        public EnumZeroCodeControlDefaultValueConfigWorkSheetMultipleType MultipleType { get; set; }

        /// <summary>
        /// 获取多少条
        /// </summary>
        public int Number { get; set; }
    }
    /// <summary>
    /// 关联表双向关联
    /// </summary>
    public class SystemDataBaseColumnsOptionCorrelationTwoWay
    {
        /// <summary>
        /// 是否是双向关联
        /// </summary>
        public bool Is { get; set; }

        /// <summary>
        /// 双向关联字段
        /// </summary>
        public string Key { get; set; }
    }
    /// <summary>
    /// 关联表双向关联字段
    /// </summary>
    public class SystemDataBaseColumnsOptionCorrelationColumns
    {
        /// <summary>
        /// 是否显示
        /// </summary>
        public bool IsShow { get; set; }

        /// <summary>
        /// 双向关联字段
        /// </summary>
        public string Key { get; set; }
    }
    /// <summary>
    /// 规则
    /// </summary>

    public class SystemDataBaseColumnsOptionRuleInput
    {
        /// <summary>
        /// 类型：field，time，character，number
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// 值
        /// </summary>
        public string Key { get; set; }

        /// <summary>
        /// number类型  长度
        /// </summary>
        public int Length { get; set; }

        /// <summary>
        /// number类型 重复类型
        /// 空 不重复
        /// day 每天重置
        /// month 每月重置
        /// year 每年重置
        /// </summary>
        public string Repeat { get; set; }

        /// <summary>
        /// number类型 开始数量
        /// </summary>
        public int BeginNumber { get; set; }

        /// <summary>
        /// number类型 编号超出位数后继续递增
        /// 勾选时，超出位数继续递增； 取消勾选时，超出位数后从0开始编号
        /// </summary>
        public bool Incremental { get; set; }

    }

    /// <summary>
    /// 
    /// </summary>
    public class SystemDataBaseColumnJsonInput
    {
        /// <summary>
        /// 字段名称
        /// </summary>
        public string Model { get; set; }

        /// <summary>
        /// 数据类型
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// 描述
        /// </summary>
        public string Label { get; set; }

        /// <summary>
        /// 值
        /// </summary>
        public dynamic Options { get; set; }
    }

    /// <summary>
    /// 
    /// </summary>
    public class SystemDataBaseColumnsOptionOptionsInput
    {
        /// <summary>
        /// 
        /// </summary>
        public string Value { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Label { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Color { get; set; }
    }

}